package com.cgs.query.util

import org.apache.commons.beanutils.ConvertUtilsBean2

class CastUtils {

    companion object {

        private val cv = ConvertUtilsBean2()

        fun any2String(any: Any?, default: String = ""): String {

            return if ((any as? String) == null) {
                default
            } else {
                any
            }
        }

        fun any2Int(any: Any?, default: Int = 0): Int {

            return if ((any as? Int) == null) {
                default
            } else {
                any
            }
        }

        fun <T> cast(value: Any?, clazz: Class<T>): T? {
            return value?.let { cv.convert(it, clazz) as T }
        }
    }
}